from Rule import Rule
import re


class Work:

    def __init__(self, formNo, title, piid, tkiid, isWarnClear, state, classOneName):
        self.formNo = formNo
        self.title = title
        self.piid = piid
        self.tkiid = tkiid
        self.isWarnClear = isWarnClear
        self.state = state
        self.classOneName = classOneName
        # 二级网络在打点时用不到。
        self.classTwoName = ''

    # state == '2', 未受理； state == '8', 已受理。

    # 工单首先受理，然后打点，然后回复。

    def __str__(self):
        return '{}, {}, {}'.format(self.title, self.isWarnClear, self.state)

    def isWarnCleard(self):
        # 告警是否清除。
        return self.isWarnClear == '是'

    def isDealt(self):
        # 告警是否已被受理。
        # 有可能通过PC受理工单。
        return self.state == '8'

    def getRule(self) -> Rule:
        for rule in Rule.rules:
            res = re.match(rule.pattern, self.title)
            if res is not None:
                return rule
        return Rule('None', 'None', 'None', 'None', 'None')
